﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Timers;

namespace RAD
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //doesnt allow user to choose target. must be random 
            birdbtn.Enabled = false;
            Missilebtn.Enabled = false;
            Planebtn.Enabled = false;
            Shipbtn.Enabled = false;

            //reset RAD_Event to blank on load
            Target target = new Target();
            XmlSerializer serializer = new XmlSerializer(typeof(Target));
            string FilePath = "../../RAD_Event/Rad_Event.xml";
            target = (Target)Utility.XMLRead(FilePath, serializer);

            target.TargetType = "";
            target.targetDistance = "";
            target.targetSpeed = "";
            target.targetAltitude = "";
            target.targetDirection = "";

            Utility.WriteXML(target, FilePath, serializer);
        }
        #region Radar_Buttons
        private void lockonbtn_Click(object sender, EventArgs e)
        {
            //Writes randomized values to RAD_Event for Com to read.
            Target target = new Target();
            XmlSerializer serializer = new XmlSerializer(typeof(Target));
            string FilePath = "../../RAD_Event/Rad_Event.xml";

            target = (Target)Utility.XMLRead(FilePath, serializer);
            target.TargetType = Convert.ToString(lblTarget.Text);
            target.targetDistance = Convert.ToString(lblDistance.Text);
            target.targetSpeed = Convert.ToString(lblSpeed.Text);
            target.targetAltitude = Convert.ToString(lblAltitude.Text);
            target.targetDirection = Convert.ToString(lblDirection.Text);

            Utility.WriteXML(target, FilePath, serializer);

            lblTarget.Text = null;
            lblDistance.Text = null;
            lblSpeed.Text = null;
            lblAltitude.Text = null;
            lblDirection.Text = null;
        }

        private void resetbtn_Click(object sender, EventArgs e)
        {
            //Clears textboxes
            lblTarget.Text = null;
            lblAltitude.Text = null;
            lblDirection.Text = null;
            lblSpeed.Text = null;
            lblDistance.Text = null;
        }

        private void ranbtn_Click(object sender, EventArgs e)
        {
            Random RandomNumber = new Random();
            int numpick = RandomNumber.Next(5);
            //lockonbtn.Enabled = false;

            switch (numpick)
            {
                case 1:
                    birdbtn.Checked = true;
                    Missilebtn.Checked = false;
                    Planebtn.Checked = false;
                    Shipbtn.Checked = false;
                    break;
                case 2:
                    birdbtn.Checked = false;
                    Missilebtn.Checked = true;
                    Planebtn.Checked = false;
                    Shipbtn.Checked = false;
                    break;
                case 3:
                    birdbtn.Checked = false;
                    Missilebtn.Checked = false;
                    Planebtn.Checked = true;
                    Shipbtn.Checked = false;
                    break;
                case 4:
                    birdbtn.Checked = false;
                    Missilebtn.Checked = false;
                    Planebtn.Checked = false;
                    Shipbtn.Checked = true;
                    break;
            }
        }
        #endregion
        #region Target_Randomize
        private void birdbtn_CheckedChanged(object sender, EventArgs e)
        {
            if (birdbtn.Checked)
            {
                //Bird target information, shows the user the informaton of the target 
                int birdspeed = BogieInformation.RandomNumber(10, 45);
                int birdaltitude = BogieInformation.RandomNumber(200, 500);
                int birddistance = BogieInformation.RandomNumber(3000, 6000);
                int birddirection = BogieInformation.RandomNumber(0, 360);
                lblSpeed.Text = Convert.ToString(birdspeed);
                lblAltitude.Text = Convert.ToString(birdaltitude);
                lblDistance.Text = Convert.ToString(birddistance);
                lblDirection.Text = Convert.ToString(birddirection);
                lblTarget.Text = "Bird";
            }
            else if (!birdbtn.Checked)
            {
                //Sets the checks to null.
                lblSpeed.Text = null;
                lblAltitude.Text = null;
                lblDistance.Text = null;
                lblDirection.Text = null;
                lblTarget.Text = null;
            }
        }

        private void Missilebtn_CheckedChanged(object sender, EventArgs e)
        {
            if (Missilebtn.Checked)
            {
                //Missile target information, shows the user the informaton of the target
                int missilespeed = BogieInformation.RandomNumber(2200, 8000);
                int missilealtitude = BogieInformation.RandomNumber(200, 500);
                int missiledistance = BogieInformation.RandomNumber(3000, 6000);
                int missiledirection = BogieInformation.RandomNumber(0, 360);
                lblSpeed.Text = Convert.ToString(missilespeed);
                lblAltitude.Text = Convert.ToString(missilealtitude);
                lblDistance.Text = Convert.ToString(missiledistance);
                lblDirection.Text = Convert.ToString(missiledirection);
                lblTarget.Text = "Missile";
            }
            else if (!Missilebtn.Checked)
            {
                //Sets the checks to null.
                lblSpeed.Text = null;
                lblAltitude.Text = null;
                lblDistance.Text = null;
                lblDirection.Text = null;
                lblTarget.Text = null;
            }
        }

        private void Planebtn_CheckedChanged(object sender, EventArgs e)
        {
            if (Planebtn.Checked)
            {
                //Plane target information, shows the user the informaton of the target
                int planespeed = BogieInformation.RandomNumber(500, 600);
                int planealtitude = BogieInformation.RandomNumber(2000, 3000);
                int planedistance = BogieInformation.RandomNumber(3000, 6000);
                int planedirection = BogieInformation.RandomNumber(0, 360);
                lblSpeed.Text = Convert.ToString(planespeed);
                lblAltitude.Text = Convert.ToString(planealtitude);
                lblDistance.Text = Convert.ToString(planedistance);
                lblDirection.Text = Convert.ToString(planedirection);
                lblTarget.Text = "Plane";
            }
            else if (!Planebtn.Checked)
            {
                //Sets the checks to null.
                lblSpeed.Text = null;
                lblAltitude.Text = null;
                lblDistance.Text = null;
                lblDirection.Text = null;
                lblTarget.Text = null;
            }
        }

        private void Shipbtn_CheckedChanged(object sender, EventArgs e)
        {
            if (Shipbtn.Checked)
            {
                //Ship target information, shows the user the informaton of the target
                int shipspeed = BogieInformation.RandomNumber(10, 30);
                int shipaltitude = BogieInformation.RandomNumber(200, 500);
                int shipdistance = BogieInformation.RandomNumber(3000, 6000);
                int shipdirection = BogieInformation.RandomNumber(0, 360);
                lblSpeed.Text = Convert.ToString(shipspeed);
                lblAltitude.Text = Convert.ToString(shipaltitude);
                lblDistance.Text = Convert.ToString(shipdistance);
                lblDirection.Text = Convert.ToString(shipdirection);
                lblTarget.Text = "Ship";
            }
            else if (!Shipbtn.Checked)
            {
                //Set the checks to null.
                lblSpeed.Text = null;
                lblAltitude.Text = null;
                lblDistance.Text = null;
                lblDirection.Text = null;
                lblTarget.Text = null;
            }
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            //Updates RAD_Status with the current time for COM to read.
            Status radarStatus = new Status();
            radarStatus.radarStatus = Convert.ToString(DateTime.Now);

            XmlSerializer serializer = new XmlSerializer(typeof(Status));
            string fileSave = "../../XML/RAD_Status.xml";
            Utility.WriteXML(radarStatus, fileSave, serializer);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void dirbox_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

    